import {createRouter, createWebHistory} from 'vue-router'
//import Home from "@/view/home.vue" @就是从src开始绝对路径
import Home from "../view/home.vue" //相对路径
import Login from "../view/login.vue";
import Register from "../view/register.vue";
import NotFound from "../view/404.vue"

// 默认第一个path就是打开网站的首页
const routes = [{
  path: "/",
  redirect: "/login"
}, {
  path: "/login",
  component: Login
}, {
  path: "/home",
  component: Home
},
 {
  path: "/register",
  component: Register
},
{
	path: "/404",
	name: "NotFound",
	component: NotFound
},
{
	path: '/:pathMatch(.*)*',
	redirect: "/404"
}

]

const router = createRouter({
  history: createWebHistory(),
  routes
})


/* 
登录验证
router.beforeEach((to, from, next) => {
	if (to.name != "Login") {
		let permissions = localStorage.getItem("permissions")
		let token = localStorage.getItem("token")
		if (permissions == null || permissions == "" || token == null || token == "") {
			next({
				name: 'Login'
			})
		}
	}
	return next()
})
 */


export default router
